#include "any_header.h"
#include "verify_shared_lib.hpp"
#include <memory>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <iostream>

#define CHECK(x) ((x)? (void)(0) : (void(fprintf(stdout, "Failed at %d:%s: %s\n", __LINE__, __FILE__, #x)), std::exit(EXIT_FAILURE)))

int main()
{
    {
        string myStr = "string in app";
        any str = myStr;
        cout<<"App: directly use any in app - " << any_cast<string>(str)<<endl;
        CHECK(UseStringInLib(str));
        CHECK(UseStringRefInLib(str));
    }
    {
        any str;
        CHECK(GetStringInLib(str));
        cout<<"App: GetStringInLib " << any_cast<string>(str)<<endl;
    }
    {
        any str = GetStringRetInLib();
        cout<<"App: GetStringRetInLib " << any_cast<string>(str)<<endl;
    }
    {
        int a = 5;
        CHECK(UseIntInLib(a));
    }
    {
        bool except = false;
        try {
            float a = 5.5;
            CHECK(UseIntInLib(a)); // should throw exception
        } catch (const bad_any_cast &) {
            except = true;
        }
        CHECK(except);
    }
    return 0;
}